﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Managers {
    import flash.events.*;
    import Engine.Interfaces.*;
    import __AS3__.vec.*;
    import flash.text.*;
    import Engine.Display.*;
    import Engine.Classes.EasterEggs.*;

    public class EasterEggManager {

        protected static var m_instance:EasterEggManager = null;

        protected var m_enabledEasterEggs:Vector.<IEasterEgg>;
        protected var m_keysEntered:Array;
        protected var m_easterEggMode:Boolean = false;
        protected var m_easterEggText:TextField;

        public function EasterEggManager(){
            this.m_enabledEasterEggs = new Vector.<IEasterEgg>();
            this.m_keysEntered = [];
            super();
            this.addEasterEgg(new CreditsEasterEgg());
        }
        public static function get instance():EasterEggManager{
            if (m_instance == null){
                m_instance = new (EasterEggManager)();
            };
            return (m_instance);
        }

        protected function addEasterEgg(_arg1:IEasterEgg):void{
            this.m_enabledEasterEggs.push(_arg1);
        }
        protected function removeEasterEgg(_arg1:String):void{
            var _local2:int;
            while (_local2 < this.m_enabledEasterEggs.length) {
                if (this.m_enabledEasterEggs[_local2].code == _arg1){
                    this.m_enabledEasterEggs.splice(_local2, 1);
                    break;
                };
                _local2++;
            };
        }
        public function processKeyStroke(_arg1:KeyboardEvent):void{
            var _local2:String;
            var _local3:String;
            if ((((_arg1.keyCode == 192)) && ((this.m_easterEggMode == false)))){
                this.enterEasterEggMode();
            } else {
                if (((this.m_easterEggMode) && ((_arg1.keyCode == 8)))){
                    this.m_keysEntered.pop();
                    this.updateText();
                } else {
                    if (((this.m_easterEggMode) && ((_arg1.keyCode == 13)))){
                        if (this.m_keysEntered.length > 0){
                            _local2 = this.m_keysEntered.join("");
                            this.easterEgg(_local2);
                        };
                        this.exitEasterEggMode();
                    } else {
                        if (this.m_keysEntered.length > 50){
                            this.exitEasterEggMode();
                        } else {
                            if (this.m_easterEggMode){
                                _local3 = String.fromCharCode(_arg1.charCode);
                                this.m_keysEntered.push(_local3);
                                this.updateText();
                            };
                        };
                    };
                };
            };
        }
        protected function updateText():void{
            if (this.m_easterEggText != null){
                this.m_easterEggText.text = ("Code: " + this.m_keysEntered.join(""));
            };
        }
        protected function enterEasterEggMode():void{
            this.m_keysEntered = [];
            this.m_easterEggMode = true;
            var _local1:TextFormat = new TextFormat(null, 12, 0xFFFFFF, true);
            this.m_easterEggText = new StrokeTextField(0, 0.8);
            this.m_easterEggText.setTextFormat(_local1);
            this.m_easterEggText.background = true;
            this.m_easterEggText.backgroundColor = 0xFFFFFF;
            this.m_easterEggText.y = 10;
            this.m_easterEggText.x = 10;
            this.updateText();
            GlobalEngine.stage.addChild(this.m_easterEggText);
        }
        protected function exitEasterEggMode():void{
            this.m_keysEntered = [];
            this.m_easterEggMode = false;
            GlobalEngine.stage.removeChild(this.m_easterEggText);
        }
        protected function easterEgg(_arg1:String):void{
            var _local2:int;
            while (_local2 < this.m_enabledEasterEggs.length) {
                if (this.m_enabledEasterEggs[_local2].code == _arg1){
                    this.m_enabledEasterEggs[_local2].execute();
                    break;
                };
                _local2++;
            };
        }

    }
}//package Engine.Managers 
